<?php

session_start();

include_once "src/controller/blmanagement/UserAccountManagement.php";
include_once "src/model/User.php";
include_once "src/misc/ClientReponseGenerator.php";

try {
    
    $name = $_POST["newUsername"];
    $type = 3;
    $pswd = $_POST["newPassword"];
    $email = $_POST["newEmail"];

    $user = new User();
    $user->setName($name);
    $user->setType($type);
    $user->setPswd($pswd);
    $user->setEmail($email);

    if (UserAccountManagement::addUser($user)) {
        $_SESSION["email"] = $email;
        $_SESSION["username"] = $name;
        echo ClientReponseGenerator::simpleJsonResponse(1, "", "");
    } else {
        throw new Exception();
    }

} catch (Exception $e) {
    echo ClientReponseGenerator::simpleJsonResponse(0, "CreateNewUserException", "");
}

?>
